package coin.yang.thread;

public class DeadLockDemo {

    private static Printer p = new Printer();
    private static Scanner s = new Scanner();

    public static void main(String[] args) {

        new Thread(() -> {
            // 第一个员工需要先打印一些文件，然后找到了打印机
            synchronized (p) {
                p.print();
                try {
                    Thread.sleep(3000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                synchronized (s) {
                    s.scan();
                }
            }
        }).start();

        new Thread(() -> {
            // 第二个员工需要先将照片扫描到电脑上
            synchronized (s) {
                s.scan();
                try {
                    Thread.sleep(3000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                synchronized (p) {
                    p.print();
                }
            }
        }).start();

    }

}

// 打印机
class Printer {
    public void print() {
        System.out.println("打印机在吱哟吱哟的打印~~~");
    }
}

// 扫描仪
class Scanner {
    public void scan() {
        System.out.println("扫描仪在哼哧哼哧的扫描~~~");
    }
}